package com.theo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    // 视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("epidemic");
        registry.addViewController("/charts").setViewName("epidemic");
        registry.addViewController("/tologin").setViewName("user/login");
        registry.addViewController("/toRegister").setViewName("user/register");
        registry.addViewController("/news-info/toNews").setViewName("user/news");
        registry.addViewController("/main.do").setViewName("admin/main");
        registry.addViewController("/epidemic-info/input.do").setViewName("admin/data_input");
        registry.addViewController("/epidemic-info/query.do").setViewName("admin/epidemic_list");
        registry.addViewController("/testPage").setViewName("testPage");
        registry.addViewController("/testPage2").setViewName("testPage2");
        registry.addViewController("/testRowCol").setViewName("test/testRowCol");
        registry.addViewController("/testChart").setViewName("test/echarts_demo04");
        registry.addViewController("/testChart2").setViewName("test/echarts_demo05");
        registry.addViewController("/testChart3").setViewName("test/echarts_demo05_5");
        registry.addViewController("/testChart4").setViewName("test/echarts_demo03_5");
        registry.addViewController("/testCity").setViewName("test/test_city");
        registry.addViewController("/testGlobal").setViewName("test/echarts_demo01_5");
    }

    /*@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }*/

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/statics/**").addResourceLocations("classpath:/statics/");
        // 解决 SWAGGER2 404报错
        registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    /*@Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }*/
    // 拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerIntercepter())
                .addPathPatterns("/**.do")
                .addPathPatterns("/*/**.do");
    }
}
